<!--
 * @Description: 编辑短信配置
 * @version: 电子名片2.0
 * @Author: 尹鑫
 * @Date: 2020-12-07 14:06:54
 * @LastEditors: 尹鑫
 * @LastEditTime: 2020-12-24 10:10:04
-->

<template>
  <el-dialog
    width="570px"
    title="编辑短信配置"
    style="margin-top: -10vh;"
    :visible.sync="_isShow"
    :close-on-click-modal="false"
    @close="closeModal"
  >
    <el-form
      ref="refForm"
      style="padding-right: 40px"
      :model="_formData"
      label-width="120px"
      :rules="formVerify"
      :validate-on-rule-change="false"
    >
      <el-form-item label="项目key：" prop="projectKey">
        <el-input v-model="_formData.projectKey" autocomplete="off" :disabled="true" />
      </el-form-item>
      <el-form-item label="访问id：" prop="accessKeyId">
        <el-input v-model="_formData.accessKeyId" autocomplete="off" />
      </el-form-item>
      <el-form-item label="访问秘钥：" prop="accessKeySecret">
        <el-input v-model="_formData.accessKeySecret" autocomplete="off" />
      </el-form-item>
      <el-form-item label="验证码长度：" prop="codeLength">
        <el-input v-model="_formData.codeLength" autocomplete="off" />
      </el-form-item>
      <el-form-item label="连接超时时间：" prop="connectTimeout">
        <el-input v-model="_formData.connectTimeout" autocomplete="off" />
      </el-form-item>
      <el-form-item label="产品域名：" prop="domain">
        <el-input v-model="_formData.domain" autocomplete="off" />
      </el-form-item>
      <el-form-item label="有效时间：" prop="expireMinute">
        <el-input v-model="_formData.expireMinute" autocomplete="off" />
      </el-form-item>
      <el-form-item label="介绍：" prop="introduce">
        <el-input v-model="_formData.introduce" autocomplete="off" />
      </el-form-item>
      <el-form-item label="产品名称：" prop="product">
        <el-input v-model="_formData.product" autocomplete="off" />
      </el-form-item>
      <el-form-item label="读超时时间：" prop="readTimeout">
        <el-input v-model="_formData.readTimeout" autocomplete="off" />
      </el-form-item>
      <el-form-item label="短信签名：" prop="signName">
        <el-input v-model="_formData.signName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="短信模板：" prop="templateCode">
        <el-input v-model="_formData.templateCode" autocomplete="off" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="onSubmit"> 提交 </el-button>
      <el-button @click="_isShow = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { smsConfigRules } from '@/views/basics/count'
// 接口
import { editSmsConfig } from '@/api/basics'
export default {
  props: {
    // 弹窗显示
    show: {
      type: Boolean,
      default: false
    },
    // 表单数据
    formData: {
      type: Object,
      default: () => {
        return {
          accessKeyId: '',
          accessKeySecret: '',
          codeLength: '',
          connectTimeout: '',
          domain: '',
          expireMinute: '',
          introduce: '',
          product: '',
          projectKey: '',
          readTimeout: '',
          signName: '',
          templateCode: ''
        }
      }
    }
  },
  data() {
    return {
      formVerify: smsConfigRules
    }
  },
  computed: {
    _isShow: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    },
    _formData: {
      get() {
        return this.formData
      },
      set(val) {
        this.$emit('update:formData', val)
      }
    }
  },
  methods: {
    closeModal() {
      this.$refs.refForm.resetFields()
    },
    onSubmit() {
      try {
      // 验证表单是否填写完善
        this.$refs.refForm.validate(async(valid) => {
          if (valid) {
            console.log(this._formData)
            const { data } = await editSmsConfig(this._formData)
            if (data) {
              this.$message({ message: '操作成功', type: 'success' })
              this._isShow = false
            } else {
              this.$message({ message: '操作失败', type: 'error' })
            }
            // this.$emit('submit', this._formData)
          }
          this.$emit('submit')
        })
      } catch (e) {
        console.log(e)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
